package bz.ziro.kanbe.controller.mng.agent;

import java.util.Date;
import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.BeanUtil;

import bz.ziro.kanbe.dao.UserAgentDao;
import bz.ziro.kanbe.model.UserAgent;
import bz.ziro.kanbe.util.KeyFactory;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * エージェント追加
 * @author Administrator
 */
public class AddController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(AddController.class.getName());

    @Override
    public Navigation run() {
        
        UserAgent agent = new UserAgent();
        
        //キー設定
        Key key = KeyFactory.allocateAgentKey();
        agent.setKey(key);
        BeanUtil.copy(request, agent);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        Date nowDate = new Date();
        //作成日を設定
        agent.setCreateDate(nowDate);
        agent.setCreator(user);

        //追加する
        UserAgentDao.insert(agent);
        return null;
    }
}
